package com.celebracion.util;

import net.pocketmagic.android.eventinjector.Events;
import net.pocketmagic.android.eventinjector.Events.InputDevice;
import android.util.Log;

public class MonitorHandler {
	
	private static Thread lectorEventos=null;
	private static boolean m_bMonitorOn=false; 
	private static Events events;
	
	
	
	
	public static void startMonitor()
	{
		
		if(!m_bMonitorOn)
			initilizeLectorEventos();
	}
	
	public static void finalizeMonitor(){
		m_bMonitorOn=false;
	}
	private static void initilizeLectorEventos(){
		Events.intEnableDebug(1);
		events = new Events();
		m_bMonitorOn=true;
		 events.Init();
	     for (InputDevice idev:events.m_Devs)
	     	idev.Open(true);
		lectorEventos = new Thread(new Runnable() {
			public void run() {
				while (m_bMonitorOn) {
					for (InputDevice idev:events.m_Devs) {
						
						//getPolligEvent() pide el ultimo evento generado
						//BTN_TOUCH DOWN
						if(idev.getOpen() && (0 == idev.getPollingEvent()) && idev.getName().contains("PixArt")){
							if( idev.getSuccessfulPollingCode()==272 )//{
								if(idev.getSuccessfulPollingType()==1)
									//Log.e("BTN_TOUCH","0");
									idev.SendTouchButton(idev.getSuccessfulPollingValue()==1);
								
									//Log.e("BTN_TOUCH",idev.getSuccessfulPollingValue()+"");
							//}else if(idev.getSuccessfulPollingCode()!=0)
								//Log.e(idev.getPath()+"", idev.getSuccessfulPollingCode()+" "+idev.getSuccessfulPollingType()+" "+idev.getSuccessfulPollingValue());
							
						}
						
						
								
							
						
						
					}
				}
			}
		});
		lectorEventos.start();    
	}

}
